﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Diagnostics;

namespace SimpleIR
{
	/// <summary>
	/// This class represents array types that appears in the program.
	/// </summary>
	public class IRArrayType : IRClassType
	{
		/// <summary>
		/// The type of the contents stored in this container
		/// </summary>
		public readonly IRType ArrayContentsType;

		/// <summary>
		/// The field that holds all the contents of this container
		/// </summary>
		private IRMemberField m_contentsfield;

		/// <summary>
		/// The field that holds that cardinality of the contianer
		/// </summary>
		private IRMemberField m_cardfield;

		public IRArrayType(int typeid, string tnamespace, string tbasename, TypeQualifiers tqual, IRType contentstype)
			: base(typeid, tnamespace, tbasename, tqual)
		{
			this.ArrayContentsType = contentstype;

			this.m_contentsfield = null;
			this.m_cardfield = null;
		}

		/// <summary>
		/// After constructing the needed fields finish constructing the array.
		/// </summary>
		public void SetFields(IRMemberField contentsf, IRMemberField cardf)
		{
			this.m_contentsfield = contentsf;
			this.m_cardfield = cardf;
		}

		/// <summary>
		/// The field that holds that cardinality of the contianer
		/// </summary>
		public IRMemberField CardField
		{ get { return this.m_cardfield; } }

		/// <summary>
		/// The field that holds all the contents of this container
		/// </summary>
		public IRMemberField ContentsField
		{ get { return this.m_contentsfield; } }
	}

	/// <summary>
	/// A special class for boxed types.
	/// </summary>
	public sealed class IRBoxedType : IRClassType
	{
		/// <summary>
		/// The enclosed valuetype.
		/// </summary>
		public readonly IRValueType BoxedTypeValue;

		private IRMemberField m_boxedfield;

		public IRBoxedType(int typeid, string tnamespace, string tbasename, TypeQualifiers tqual, IRValueType boxedtype)
			: base(typeid, tnamespace, tbasename, tqual)
		{
			this.BoxedTypeValue = boxedtype;
			this.m_boxedfield = null;
		}

		/// <summary>
		/// After constructing the needed fields finish constructing the array.
		/// </summary>
		public void SetField(IRMemberField bvf)
		{ this.m_boxedfield = bvf; }

		public IRMemberField BoxedValueField
		{ get { return this.m_boxedfield; } }
	}

	/// <summary>
	/// This class represents the delegate/lambda types in the program.
	/// </summary>
	public sealed class IRLambdaType : IRClassType
	{
		public IRLambdaType(int typeid, string tnamespace, string tbasename, TypeQualifiers tqual)
			: base(typeid, tnamespace, tbasename, tqual)
		{ ;}
	}
}
